package cn.tedu.xuecha.boot;

import org.mybatis.spring.annotation.MapperScan;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author coinyang
 * @date 2023/5/4 20:11
 */
@SpringBootApplication(scanBasePackages = "cn.tedu")
@MapperScan(basePackages = "cn.tedu.xuecha.dao")
@EnableWebMvc
public class Application implements WebMvcConfigurer {
    private static Logger log = LoggerFactory.getLogger(Application.class);

    public static void main(String[] args) {
        SpringApplication springApplication = new SpringApplication(Application.class);


//        springApplication.addListeners(new ApplicationListener<ContextRefreshedEvent>() {
//            @Override
//            public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
//                log.info("application startup at {}", contextRefreshedEvent.getTimestamp());
//            }
//        });
//        springApplication.addListeners(new ApplicationListener<ContextClosedEvent>() {
//            @Override
//            public void onApplicationEvent(ContextClosedEvent contextClosedEvent) {
//                log.info("application closed at at {}", contextClosedEvent.getTimestamp());
//            }
//        });
        springApplication.run(args);
    }

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("doc.html").addResourceLocations("classpath:/META-INF/resources/");
        registry.addResourceHandler("/webjars/**").addResourceLocations("classpath:/META-INF/resources/webjars/");
    }

}
